//
//  BaseTableViewController.swift
//  weiboxiangmu
//
//  Created by wei_jingyun on 15/6/23.
//  Copyright © 2015年 wei_jingyun. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController , VisitorLoginViewDelegate {
    // 用户登录标记
    var userState = sharedUserAccount != nil
    
    // 访客视图 可以为空
    var visitotView : VisitorLoginView?

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func loadView() {
        userState ? super.loadView() : usershowView()
    }
    
    // MARK:创建访客视图
    private func usershowView(){
        visitotView = VisitorLoginView()
        view = visitotView
        // 设置代理
        visitotView?.myDelegate = self
        
        // 设置导航栏左右按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorRegisterButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginButtonClicked")

    }
    
    func visitorRegisterButtonClicked() {
        RegisterLogin(false)
    }
    
    func visitorLoginButtonClicked() {
        RegisterLogin(true)
    }
    
    // 登陆
    private func RegisterLogin(login : Bool){
        // 新浪授权页面
        let vc = OAuthViewController()
        vc.login = login
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
}
